<?php

namespace app\admin\controller;

use app\admin\model\Admin as Admin;
use think\Controller;
use think\Session;

class Login extends Controller
{

    public function login()
    {
        $admin = Admin::do_login($_POST['username'], $_POST['password']);

        if ($admin) {

            $this->success('登录成功', '/admin/index');

        }
        $this->error("登录失败，用户名或密码错误");
    }

    public function logout()
    {
        Session::delete('admin');

        $this->success('登出成功', '/admin/login');
    }

    public function index()
    {
        if (Session::has('admin')) {

            $this->redirect('/admin/index');

        }

        return view('login/login');
    }
}
